package com.sxkiler.demo.easy;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.*;
import com.sxkiler.demo.model.*;

/**
transpose-matrix=转置矩阵
<p>给定一个矩阵&nbsp;<code>A</code>，&nbsp;返回&nbsp;<code>A</code>&nbsp;的转置矩阵。</p>

<p>矩阵的转置是指将矩阵的主对角线翻转，交换矩阵的行索引与列索引。</p>

<p>&nbsp;</p>

<p><strong>示例 1：</strong></p>

<pre><strong>输入：</strong>[[1,2,3],[4,5,6],[7,8,9]]
<strong>输出：</strong>[[1,4,7],[2,5,8],[3,6,9]]
</pre>

<p><strong>示例 2：</strong></p>

<pre><strong>输入：</strong>[[1,2,3],[4,5,6]]
<strong>输出：</strong>[[1,4],[2,5],[3,6]]
</pre>

<p>&nbsp;</p>

<p><strong>提示：</strong></p>

<ol>
	<li><code>1 &lt;= A.length&nbsp;&lt;= 1000</code></li>
	<li><code>1 &lt;= A[0].length&nbsp;&lt;= 1000</code></li>
</ol>

 */
public class transpose {
    

    class Solution {

        public Integer[][] transpose(Integer[][] param0) {
            int lenLine = param0.length;
            int lenRow = param0[0].length;
            Integer [][] param1 = new Integer[lenRow][lenLine];
            for(int i=0;i<lenLine;i++){
                for(int j=0;j<lenRow;j++){
                    param1[j][i] = param0[i][j];
                }
            }
            return param1;
        }
    }

    @Test
    public void test(){
        Solution solution = new Solution();
        Integer[][] param0 = new Integer[][]{{1,2,3}, {4,5,6},{7,8,9}};
        Integer[][] param1 = new Integer[][]{{1,4,7}, {2,5,8},{3,6,9}};
        /**
        [[1,2,3],[4,5,6],[7,8,9]]
        */
        //int [] num1 = new int[]{1,3};
        //int [] num2 = new int[]{2};
        Assertions.assertArrayEquals(solution.transpose(param0),param1);
    }
}

